package Algorithm;

import java.util.ArrayList;
import java.util.Arrays;

public class TheSumOfTwoNumber {
    public static int[] findNumber(int[] array,int target){
        int left=0,right=array.length-1;
        int[] res=new int[2];
        while(left<right){
            if(array[left]+array[right]==target){
                res[0]=left;
                res[1]=right;
                left++;
            }else if(array[left]+array[right]>target){
                right--;
            }else if(array[left]+array[right]<target){
                left++;
            }
        }
        return res;
    }
    public static void main(String[] args) {
        int[] array=new int[]{2,7,11,15};
        int[] res=findNumber(array,9);
        Arrays.sort(array);
        for(int element:res){
            System.out.print(element+" ");
        }
    }
}
